/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author dingnangen
 */
@Entity
@Table(name = "problem")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Problem.findAll", query = "SELECT p FROM Problem p"),
    @NamedQuery(name = "Problem.findByIdproblem", query = "SELECT p FROM Problem p WHERE p.idproblem = :idproblem"),
    @NamedQuery(name = "Problem.findByCreatedate", query = "SELECT p FROM Problem p WHERE p.createdate = :createdate"),
    @NamedQuery(name = "Problem.findByReadyTime", query = "SELECT p FROM Problem p WHERE p.readyTime = :readyTime"),
    @NamedQuery(name = "Problem.findByDueDate", query = "SELECT p FROM Problem p WHERE p.dueDate = :dueDate"),
    @NamedQuery(name = "Problem.findByFordate", query = "SELECT p FROM Problem p WHERE p.fordate = :fordate")})
public class Problem implements Serializable {

    @JoinColumn(name = "idsolution", referencedColumnName = "idsolution")
    @OneToOne
    private Solution idsolution;

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idproblem")
    private Integer idproblem;
    @Basic(optional = false)
    @NotNull
    @Column(name = "createdate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdate;
    @Column(name = "readyTime")
    @Temporal(TemporalType.TIME)
    private Date readyTime;
    @Column(name = "dueDate")
    @Temporal(TemporalType.TIME)
    private Date dueDate;
    @Column(name = "fordate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fordate;
    @JoinTable(name = "problem_attendance", joinColumns = {
        @JoinColumn(name = "idproblem", referencedColumnName = "idproblem")}, inverseJoinColumns = {
        @JoinColumn(name = "idattendance", referencedColumnName = "idattendance")})
    @ManyToMany//(mappedBy = "problemList")
    private List<Attendance> attendanceList;
    @JoinTable(name = "problem_customerdemand", joinColumns = {
        @JoinColumn(name = "idproblem", referencedColumnName = "idproblem")}, inverseJoinColumns = {
        @JoinColumn(name = "idcustomerdemand", referencedColumnName = "idcustomerdemand")})
    @ManyToMany//(mappedBy = "problemList")
    private List<Customerdemand> customerdemandList;
    @JoinColumn(name = "iddepot", referencedColumnName = "iddepot")
    @ManyToOne(optional = false)
    private Depot iddepot;
    @JoinColumn(name = "iduser", referencedColumnName = "iduser")
    @ManyToOne
    private User iduser;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idproblem")
    private List<Solution> solutionList;

    public Problem() {
    }

    public Problem(Integer idproblem) {
        this.idproblem = idproblem;
    }

    public Problem(Integer idproblem, Date createdate) {
        this.idproblem = idproblem;
        this.createdate = createdate;
    }

    public Integer getIdproblem() {
        return idproblem;
    }

    public void setIdproblem(Integer idproblem) {
        this.idproblem = idproblem;
    }

    public Date getCreatedate() {
        return createdate;
    }

    public void setCreatedate(Date createdate) {
        this.createdate = createdate;
    }

    public Date getReadyTime() {
        return readyTime;
    }

    public void setReadyTime(Date readyTime) {
        this.readyTime = readyTime;
    }

    public Date getDueDate() {
        return dueDate;
    }

    public void setDueDate(Date dueDate) {
        this.dueDate = dueDate;
    }

    public Date getFordate() {
        return fordate;
    }

    public void setFordate(Date fordate) {
        this.fordate = fordate;
    }

    @XmlTransient
    public List<Attendance> getAttendanceList() {
        return attendanceList;
    }

    public void setAttendanceList(List<Attendance> attendanceList) {
        this.attendanceList = attendanceList;
    }

    @XmlTransient
    public List<Customerdemand> getCustomerdemandList() {
        return customerdemandList;
    }

    public void setCustomerdemandList(List<Customerdemand> customerdemandList) {
        this.customerdemandList = customerdemandList;
    }

    public Depot getIddepot() {
        return iddepot;
    }

    public void setIddepot(Depot iddepot) {
        this.iddepot = iddepot;
    }

    public User getIduser() {
        return iduser;
    }

    public void setIduser(User iduser) {
        this.iduser = iduser;
    }

    @XmlTransient
    public List<Solution> getSolutionList() {
        return solutionList;
    }

    public void setSolutionList(List<Solution> solutionList) {
        this.solutionList = solutionList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idproblem != null ? idproblem.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Problem)) {
            return false;
        }
        Problem other = (Problem) object;
        if ((this.idproblem == null && other.idproblem != null) || (this.idproblem != null && !this.idproblem.equals(other.idproblem))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.entity.Problem[ idproblem=" + idproblem + " ]";
    }

    public Solution getIdsolution() {
        return idsolution;
    }

    public void setIdsolution(Solution idsolution) {
        this.idsolution = idsolution;
    }
    
}
